/**
 * @param {number[]} nums
 * @param {number} key
 * @return {number}
 */
 var mostFrequent = function(nums, key) {
  let mp = new Map()
  for(let i = 1; i<nums.length; i++) {
    if(nums[i-1] === key) {
      mp.set(nums[i], (mp.get(nums[i]) || 0) + 1)
    }
  }
  let arr = [...mp.keys()].sort((a,b) => mp.get(b)-mp.get(a))
  return arr[0]
};